const util = require('../../utils/util.js')
let globalData = getApp().globalData
Page({
  data: {
    disabled: false,
    
    username: "",
    type:"primary",
    code:""
  },
  onLoad: function(options) {},
  input: function(e) {
    this.setData({
      username: e.detail.value
    });
  },
  
  reg: function(e) {
    
    let username = e.detail.value.username;
    let password= e.detail.value.password;
    let name= e.detail.value.name;
    let mobile= e.detail.value.mobile;
    let address= e.detail.value.address;
    let sex=e.detail.value.sex;
    
    if (util.isNullOrEmpty(username)) {
      util.toast('请输入账号');
      return
    } 

    //参数
    let postData = { username:username,password:password,name:name,sex:sex,mobile:mobile,address:address}

    util.request("/app/registerSave.html", postData, "get", false,  false ).then((res) => {
      if (res.msg=="操作成功") {
        util.toast("注册成功",2000, true);
        globalData.isLogin = true;
        setTimeout(()=>{
          wx.reLaunch({
            url: '/pages/login/login'
          })
        },1000);
      }else{
        console.log(res)
        util.toast('注册失败');

      }
    
      
     
    }).catch((res) => {
      console.log(res)
      util.toast('请重试');
    })

  

  
  
  }
})